<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String basePath = request.getContextPath();
%>
<html>
<head>
    <title>三级联动选择地区</title>
    <script src="<%=basePath%>/resources/js/jquery-1.8.2.min.js" type="text/javascript"></script>
    <script src="<%=basePath%>/resources/js/area/area.js" type="text/javascript"></script>
    <script src="<%=basePath%>/resources/js/area/areaData_min.js" type="text/javascript"></script>
    <script type="text/javascript">
        //初始化加载地区数据  如不需要请把后面三个参数改为0
        $(function () {
            initComplexArea('searchProv', 'searchCity', 'searchDistrict', area_array, sub_array, '44', '0', '0');
        });

        //得到地区码
        function  getAreaID() {
            var area = 0;
            if ($("#searchDistrict").val() != "0") {
                area = $("#searchDistrict").val();
            }
            else if ($("#searchCity").val() != "0") {
                area = $("#searchCity").val();
            }
            else {
                area = $("#searchProv").val();
            }
            return area;
        }

        function showAreaID() {
            //地区码
            var areaID = getAreaID();
            //地区名
            var areaName = getAreaNamebyID(areaID) ;
            alert("您选择的地区码：" + areaID + "      地区名：" + areaName);
        }

        //根据地区码查询地区名
        function getAreaNamebyID(areaID) {
            var areaName = "";
            if (areaID.length == 2) {
                areaName = area_array[areaID];
            }
            else if (areaID.length == 4) {
                var index1 = areaID.substring(0, 2);
                areaName = area_array[index1] + " " + sub_array[index1][areaID];
            }
            else if (areaID.length == 6) {
                var index1 = areaID.substring(0, 2);
                var index2 = areaID.substring(0, 4);
                areaName = area_array[index1] + " " + sub_array[index1][index2] + " " + sub_arr[index2][areaID];
            }
            return areaName;
        }
    </script>
</head>
<body>
    <select id="searchProv" name="searchProv"
        onchange="changeComplexProvince(this.value, sublocation_array, 'searchCity', 'searchDistrict', true);">
    </select>
    <select id="selectCity" name="homeCity"
        onchange="changeCity(this.value, 'searchDistrict', 'searchDistrict');"></select>
    <span id="searchDistrictDiv">
        <select id="searchDistrict" name="searchDistrict"></select>
    </span>
    <input type="button" value="获取地区码" onclick="showAreaID();">
</body>
</html>